﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class MasterPage : System.Web.UI.MasterPage
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        LeftMenu.Text = LoadMenu();
    }
    public String LoadMenu()
    {
        String LeftMenu = "";
        DataTable dTable = new DataTable();
        try
        {
            if (conn.State == System.Data.ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlDataAdapter da = new SqlDataAdapter("Select * from tb_Vacancy", conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "tbMenu");
            dTable = ds.Tables[0];
            if (dTable.Rows.Count > 0)
            {
                foreach (DataRow item in dTable.Rows)
                {
                    LeftMenu += "<a href=\"Home.aspx?id=" + item["VacancyID"] + "\">" + item["VacancyID"] + "</a>";
                }
            }
        }
        catch (Exception)
        {
            Response.Redirect("ErrorPage.aspx");
        }
        finally
        {
            conn.Close();
        }
        return LeftMenu;
    }
}
